package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.BannerDao;
import com.baizhi.cmfz.entity.Banner;
import com.baizhi.cmfz.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerDao bannerDao;
    @Override
    public Map selectByPageBanner(int page, int limit) {
        int offset=(page-1)*limit;
        List<Banner> banners = bannerDao.selectByPageBanner(offset, limit);
        int count = bannerDao.selectTotalCountBanner();
        Map map=new HashMap();
        map.put("data",banners);
        map.put("count",count);
        map.put("msg","");
        map.put("code",0);
        return map;
    }

    @Override
    public Map insertBanner(Banner banner) {
       Map map=new HashMap();
      int count = bannerDao.insertBanner(banner);
      if (count >0){
          map.put("isInsert",true);
      }else {
          map.put("isInsert",false);
      }
        return map;
    }

    @Override
    public Map deleteBanner(Integer bannerId) {
       Map map=new HashMap();
        int count= bannerDao.deleteBanner(bannerId);
       if(count>0){
           map.put("isDelete",true);
       } else {
           map.put("isDelete",false);
       }
       return map;
    }

    @Override
    public Map updateBanner(Banner banner) {
        Map map=new HashMap();
        int count = bannerDao.updateBanner(banner);
        if(count>0){
            map.put("isUpdate",true);
        }else {
            map.put("isUpdate",false);
        }
        return map;
    }

    @Override
    public Banner selectOneBanner(Integer id) {

        return bannerDao.selectOneBanner(id);
    }

    @Override
    public Map updateState(Integer id, Integer state) {

        Map map =new HashMap<>();
       int count= bannerDao.updateState(id,state);
       if (count>0){
           map.put("isUpdate",true);
       }else{
           map.put("isUpdate",false);
       }
        return map;
    }
}
